#coding=utf-8
__author__ = 'jy@cjlu.edu.cn'
from basehandler import basehandler
import os
from config import global_lookup
from config import TP_PATH
class SysLogList(basehandler):
    #@checkpower("0031")
    def get(self):
        self.set_header("Content-Type", "text/html; charset=UTF-8")
        i=self.input()
        if i.get('fn',None):
            sourceFile = os.path.join(TP_PATH+"/log/",i.fn)
            targetFile = os.path.join(TP_PATH+"/static/","syslog.txt")
            open(targetFile, "wb").write(open(sourceFile, "rb").read())
            self.redirect("/static/syslog.txt")
        else:
            pl=os.listdir(TP_PATH+"/log/")
            pp=[]
            for p in pl:
                if str(p).startswith("sys"):
                    pp.append(p)
            t=global_lookup.get_template("f00/T/sysloglist.html")
            self.write(t.render(datas=pp))
class OptLogList(basehandler):
#    @checkpower("0032")
    def get(self):
        self.set_header("Content-Type", "text/html; charset=UTF-8")
        i=self.input()
        if i.get('fn',None):
            sourceFile = os.path.join(TP_PATH+"/log/",i.fn)
            targetFile = os.path.join(TP_PATH+"/static/","optlog.txt")
            open(targetFile, "wb").write(open(sourceFile, "rb").read())
            self.redirect("/static/optlog.txt")
        else:
            pl=os.listdir(TP_PATH+"/log/")
            pp=[]
            for p in pl:
                if str(p).startswith("opt"):
                    pp.append(p)
            t=global_lookup.get_template("f00/T/optloglist.html")
            self.write(t.render(datas=pp))